package User;


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class UserDaoMap implements UserDao {
  HashMap<String ,User>map=new HashMap<>();
  public UserDaoMap(){
  }
    @Override
    public void register(User user) {
        map.put(user.getName(),user);

    }

    @Override
    public boolean login(String name, String password) {
      Iterator iterator=map.keySet().iterator();
      while(iterator.hasNext()){
          String key=(String) iterator.next();
          User value=map.get(key);
          if(name.equals(key)&&password.equals(value.getPassword())){
              return  true;
          }

      }
        return false;
    }

    @Override
    public void queryAll() {
        System.out.println("所有用户信息如下");
        Iterator iterator=map.entrySet().iterator();
        while(iterator.hasNext()){
            Map.Entry<String,User>entry=(Map.Entry<String,User>)iterator.next();
            User value=entry.getValue();
            System.out.println(value);
        }

    }
}
